package com.ruoyi.web.controller.purchase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.pojo.PurchaseReturnGoods;
import com.ruoyi.purchase.service.PurchaseReturnGoodsService;
import io.swagger.models.auth.In;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购退货清单Controller
 *
 * @author ruoyi
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/purchase/goods")
public class PurchaseReturnGoodsController extends BaseController
{
    @Autowired
    private PurchaseReturnGoodsService purchaseReturnGoodsService;

    /**
     * 查询采购退货清单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PurchaseReturnGoods purchaseReturnGoods)
    {
        startPage();
        List<PurchaseReturnGoods> list = purchaseReturnGoodsService.selectPurchaseReturnGoodsList(purchaseReturnGoods);
        return getDataTable(list);
    }

    /**
     * 导出采购退货清单列表
     */
    @Log(title = "采购退货清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseReturnGoods purchaseReturnGoods)
    {
        List<PurchaseReturnGoods> list = purchaseReturnGoodsService.selectPurchaseReturnGoodsList(purchaseReturnGoods);
        ExcelUtil<PurchaseReturnGoods> util = new ExcelUtil<PurchaseReturnGoods>(PurchaseReturnGoods.class);
        util.exportExcel(response, list, "采购退货清单数据");
    }

    /**
     * 获取采购退货清单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(purchaseReturnGoodsService.selectPurchaseReturnGoodsById(id));
    }

    /**
     * 新增采购退货清单
     */
    @Log(title = "采购退货清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseReturnGoods purchaseReturnGoods)
    {
        return toAjax(purchaseReturnGoodsService.insertPurchaseReturnGoods(purchaseReturnGoods));
    }

    /**
     * 修改采购退货清单
     */
    @Log(title = "采购退货清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseReturnGoods purchaseReturnGoods)
    {
        return toAjax(purchaseReturnGoodsService.updatePurchaseReturnGoods(purchaseReturnGoods));
    }

    /**
     * 删除采购退货清单
     */
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "采购退货清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(purchaseReturnGoodsService.deletePurchaseReturnGoodsByIds(ids));
    }
}
